frappe.query_reports["Budget Variance Report CN"] = {
    "filters": [
        {
            "fieldname": "company",
            "label": __("Company"),
            "fieldtype": "Link",
            "options": "Company",
            "default": frappe.defaults.get_user_default("Company"),
            "reqd": 1
        },
        {
            "fieldname": "fiscal_year",
            "label": __("Fiscal Year"),
            "fieldtype": "Link",
            "options": "Fiscal Year",
            "default": frappe.defaults.get_user_default("fiscal_year"),
            "reqd": 1
        },
        {
            "fieldname": "month",
            "label": __("Month"),
            "fieldtype": "Select",
            "options": ["January", "February", "March", "April", "May", "June", 
                        "July", "August", "September", "October", "November", "December"],
            "default": function() {
                const months = ["January", "February", "March", "April", "May", "June", 
                               "July", "August", "September", "October", "November", "December"];
                return months[new Date().getMonth()]; // 默认当前月份
            },
            "reqd": 1
        },
        {
            "fieldname": "cost_center",
            "label": __("Cost Center"),
            "fieldtype": "Link",
            "options": "Cost Center"
        },
        {
            "fieldname": "budget_against",
            "label": __("Budget Against"),
            "fieldtype": "Select",
            "options": ["Account", "Cost Center"],
            "default": "Account"
        },
        {
            "fieldname": "report_type",
            "label": __("Report Type"),
            "fieldtype": "Select",
            "options": [
                { "value": "Balance Sheet", "label": __("Balance Sheet") },
                { "value": "Profit and Loss", "label": __("Profit and Loss") }
            ],
            "default": "Profit and Loss"
        },
        {
            "fieldname": "root_type",
            "label": __("Root Type"),
            "fieldtype": "Select",
            "options": [
                { "value": "Asset", "label": __("Asset") },
                { "value": "Liability", "label": __("Liability") },
                { "value": "Equity", "label": __("Equity") },
                { "value": "Income", "label": __("Income") },
                { "value": "Expense", "label": __("Expense") }
            ]
        },
        {
            "fieldname": "show_zero_values",
            "label": __("Show Zero Values"),
            "fieldtype": "Check",
            "default": 0
        }
    ],
    "formatter": function(value, row, column, data, default_formatter) {
        value = default_formatter(value, row, column, data);
        // 父实体行加粗显示
        if (data && data.is_group) {
            value = `<strong>${value}</strong>`;
        }
        // 差异为负时标红
        if (column.fieldname === "variance" && data && data.variance < 0) {
            value = `<span style="color:red">${value}</span>`;
        } else if (column.fieldname === "variance_percent" && data && data.variance_percent < 0) {
            value = `<span style="color:red">${value}</span>`;
        }
        return value;
    }
};